package com.thh.shirodemo.mapper;

import com.thh.shirodemo.bean.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author shkstart
 * @create 2022-07-19-1:16
 */
@Mapper
public interface UserMapper {
    //按用户名查找用户
    @Select("select * from user where user_name=#{userName}")
    public User getUser(String userName);

    //按用户id查找用户
    @Select("select * from user where user_id=#{userId}")
    public User getUserById(Integer userId);

    //按照该用户的用户权限查找用户的资源
    @Select("select role_perm from  user_roles where role_id=#{roleId}")
    public List<String> getRoles(Integer roleId);

    //添加admin用户
    @Options(useGeneratedKeys = true,keyProperty = "userId")
    @Insert("insert into user (user_name,user_pass,user_roles) values (#{userName},#{userPass},1)")
    public boolean insertManage(User user);
}
